package com.haoxiaozi.www.GUIFunctionStudy;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-12-07
 * Time: 17:02
 */
public class GridLayout {
    public static void main(String[] args) {
        Frame frame = new Frame("hao");

        //设置为表单布局
        frame.setLayout(new java.awt.GridLayout(3,2,20,30));

        frame.setVisible(true);

        frame.setBounds(300,300,500,500);

        //组件-按键
        Button button1 = new Button("button1");
        Button button2 = new Button("button2");
        Button button3 = new Button("button3");
        Button button4 = new Button("button4");
        Button button5 = new Button("button5");
        Button button6 = new Button("button6");


        //添加按键
        frame.add(button1);
        frame.add(button2);
        frame.add(button3);
        frame.add(button4);
        frame.add(button5);
        frame.add(button6);

        //自动调整布局
        frame.pack();

        frame.addWindowListener(new WindowAdapter(){
            @Override
            public void windowClosing(WindowEvent e) {
                //结束程序
                System.exit(0);
            }
        });
    }
}
